package com.zzjson.springbootjdbc.config;

import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : 多数据源 DataSource 配置</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年11月05日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@Configuration
public class MultipleDataSourceConfiguration {

	@Bean
	@Primary
	public DataSource masterDataSource() {
		/**
		 * spring.datasource.driver-class-name=com.mysql.jdbc.Driver
		 * spring.datasource.username=root
		 * spring.datasource.password=root
		 * spring.datasource.url=jdbc:mysql://116.62.221.6:3306/TEST
		 */
		DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
		DataSource dataSource = dataSourceBuilder.
				driverClassName("com.mysql.jdbc.Driver").
				url("jdbc:mysql://116.62.221.6:3306/TEST").
				username("root").
				password("root").
				build();
		return dataSource;
	}

	@Bean
	public DataSource slaveDataSource() {
		DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
		DataSource dataSource = dataSourceBuilder.
				driverClassName("com.mysql.jdbc.Driver").
				url("jdbc:mysql://116.62.221.6:3306/TEST2").
				username("root").
				password("root").
				build();
		return dataSource;
	}
}